package com.jereh.zk.oa.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jereh.zk.oa.dao.UsersDao;
import com.jereh.zk.oa.dao.baseDao;
import com.jereh.zk.oa.entity.Users;

public class UsersDaoImpl extends baseDao implements UsersDao {

	public Users findUser(String uname, String upwd) {
		String sql="select * from users where uname=? and upwd=?";
		List params=new ArrayList();
		params.add(uname);
		params.add(upwd);
		Users user=null;
		ResultSet rs=super.executeQuery(sql, params);
		try {
			while(rs.next()){
				user=new Users();
				user.setId(rs.getInt("id"));
				user.setUname(rs.getString("uname"));
				user.setUpwd(rs.getString("upwd"));
				user.setRoleid(rs.getInt("roleid"));
				user.setDepartid(rs.getInt("departid"));
				user.setRealName(rs.getString("realName"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				rs.close();super.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return user;
	}

	public String selectRole(int roleid) {
		String sql="select role_name from role where id="+roleid;
		String rolename="";
		ResultSet rs=super.executeQuery(sql);
		try {
			while(rs.next()){
				rolename=rs.getString("role_name");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				rs.close();super.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return rolename;
	}
	
}
